package com.tracy.lifeproject.discovery.goods.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.tracy.lifeproject.R;
import com.tracy.lifeproject.bean.GoodsCategoryBean;

import java.util.List;

/**
 * Created by ZJS on 2016/7/23.
 */
public class GoodsGridViewAdapter extends BaseAdapter {

    private List<GoodsCategoryBean.DataBean.ItemsBean> mList;
    private Context mContext;

    public GoodsGridViewAdapter(Context context,List<GoodsCategoryBean.DataBean.ItemsBean> datas){
        this.mContext = context;
        this.mList = datas;
    }

    @Override
    public int getCount() {
        return mList == null?0:mList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder = null;
        if (convertView==null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_goodscategory,parent,false);
            holder = new MyViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (MyViewHolder) convertView.getTag();
        }
        GoodsCategoryBean.DataBean.ItemsBean itemsBean = mList.get(position);
        Picasso.with(mContext).load(itemsBean.getCover_image_url()).into(holder.goodsIcon);
        holder.goodsName.setText(itemsBean.getName());
        holder.goodsPrice.setText("¥"+itemsBean.getPrice());//alt+0165-->¥
        holder.goodsLike.setText(""+itemsBean.getFavorites_count());
        return convertView;
    }

    class MyViewHolder{
        private ImageView goodsIcon;
        private TextView goodsName,goodsPrice,goodsLike;
        public MyViewHolder(View v){
            goodsIcon = (ImageView) v.findViewById(R.id.image_goodsIcon);
            goodsName = (TextView) v.findViewById(R.id.txt_goodsName);
            goodsPrice = (TextView) v.findViewById(R.id.txt_goodsPrice);
            goodsLike = (TextView) v.findViewById(R.id.txt_goodsLike);
        }
    }
}
